<?php
namespace app\admin\controller;

use think\Controller;
use think\Request;
use app\common\service\User as UserService;



/**
 * 登录不需要权限检查
 * Class Login
 * @package app\admin\controller
 */
class Login extends Controller{

    public function login(Request $request){

        $input  = $request->only(['account','password']);

        if(!$input['account'] || !$input['password']){
            $this->error("帐号和密码不能为空");
        }

        $userService = new UserService();

        $passport = $userService->login($input['account'],$input['password']);

        if($passport) {
            $this->success("登录成功",'/admin/index/index');
        }

        $this->error("帐号或者密码错误");
    }

    public function logout(){

        $userService = new UserService();

        $userService->logout();

        $this->success('退出成功','/admin/login/index');
    }

    /**
     *  登录页
     */
    public function index(){

        return view();
    }
}